#!/bin/bash
# Copyright 2011 Matt Shepherd, MindPoint Group, http://www.mindpointgroup.com
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

folder=$1
infile=$2
init=$3
sname=$4

echo "Licensed under the Apache License, Version 2.0 (the 'License');"
echo "you may not use this file except in compliance with the License."
echo "You may obtain a copy of the License at"
echo "http://www.apache.org/licenses/LICENSE-2.0"
echo " "
echo "Unless required by applicable law or agreed to in writing, software"
echo "distributed under the License is distributed on an 'AS IS' BASIS,"
echo "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied."
echo "See the License for the specific language governing permissions and"
echo "limitations under the License."
if [ "$init" = "new" ]; then
	source ./vars
	./clean-all
	./pkitool --initca
	./pkitool --server $sname
fi
while read line
do
	echo "########################################"
	echo "A key will be generated for $line."
	echo "########################################"
	mkdir $folder/$line
	./pkitool $line
	cp $folder/$line.* $folder/$line/
	echo "########################################"
	echo "A key has been generated for $line."
	echo "########################################"\n
done < $infile
